/**
 * 和后台数据交互的路由
 *
 * @author bian
 * @createDate 2016.10.1
 */
// const proxy = require("koa-proxy");
const config = require("../proxy.json");
const Check = require("../lib/check").Check
const CheckNull = require("../lib/check").CheckNull
const auth = require("../instances/auth")
const uuidV4 = require("uuid/v4")

module.exports = (router) => {

    router.post("/api/admin_login",function *(){
        Check(this,"username","password")
        let ctx = this
        let body = ctx.request.body

        var adminer = {
            name : "BOSS"
        }

        var isAccountRight = body.username == "oureda" ? 1 : -1
        var isPwdRight = body.password == "oureda4321" ? 1 : -1

        if(isAccountRight == 1 && isPwdRight == 1){
            var session = uuidV4()
            auth.login(adminer,session,"adminCache")
            ctx.cookies.set('session', session,{httpOnly : false})
        }

        ctx.body = {
            isAccountRight,
            isPwdRight
        }
    })
}